from flask import Blueprint,request,render_template,redirect
from .models import *
"""
此文件用于存放路由和视图函数
"""


blue = Blueprint('user',__name__)

admin = Blueprint('admin',__name__)

@blue.route('/')
def index():
    return 'index'

@admin.route('/admin/')
def index():
    return 'admin'

@admin.route('/admin/login/', methods=['GET','POST'])
def admin_login():
    if request.method == 'GET':
        return render_template('login.html')
    elif request.method == 'POST':
        username = request.form.get('username')
        userpwd = request.form.get('userpwd')
        user = User.query.filter_by(username=username,password=userpwd).first() #
        if user:
            return render_template('index.html') # 跳转到首页

        else:
            return '用户名或密码错误'



